home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / utils / install / loaddat.h < prev    next >
Text File  |  1993-11-24  |  3KB  |  136 lines

  1. int entry_compare_dn(void *va, void *vb)
  2. {
  3.   FileEntry *a = *(FileEntry **)va;
  4.   FileEntry *b = *(FileEntry **)vb;
  5.   if (a->disk_no != b->disk_no)
  6.     return a->disk_no - b->disk_no;
  7.   return strcmp(a->file_name, b->file_name);
  8. }
  9.  
  10. int entry_compare_n(void *va, void *vb)
  11. {
  12.   FileEntry *a = *(FileEntry **)va;
  13.   FileEntry *b = *(FileEntry **)vb;
  14.   return strcmp(a->file_name, b->file_name);
  15. }
  16.  
  17. void load_data_file()
  18. {
  19.   FileEntry *last_entry = 0, *fe;
  20.   char line[1000], fname[80];
  21.   FILE *dat_file;
  22.   int i;
  23.   FileEntry **felist;
  24.  
  25.   strcpy(default_fptr, "INSTALL.DAT");
  26.   printf("Loading %s\n", default_dir);
  27.   dat_file = fopen(default_dir, "r");
  28.   if (dat_file == 0)
  29.   {
  30.     printf("Cannot load %s!\n", default_dir);
  31.     exit(1);
  32.   }
  33.   while (fgets(line, 1000, dat_file))
  34.   {
  35.     if (!isdigit(line[0]))
  36.       continue;
  37.     line[strlen(line)-1] = 0; /* strip NL */
  38.       
  39.     fe = (FileEntry *)malloc(sizeof(FileEntry));
  40.     sscanf(line, "%d %c %s %ld %n\n",
  41.       &(fe->disk_no),
  42.       &(fe->mandatory),
  43.       fname,
  44.       &(fe->size_uncompressed),
  45.       &i);
  46.     fe->description = strdup(line+i);
  47.     fe->mandatory = (fe->mandatory == 'y') || (fe->mandatory == 'Y');
  48.     fe->desired = 0;
  49.     fe->file_name = strdup(fname);
  50.     fe->next = 0;
  51.     
  52.     if (last_entry)
  53.       last_entry->next = fe;
  54.     else
  55.       file_entries = fe;
  56.     last_entry = fe;
  57.   }
  58.   fclose(dat_file);
  59. }
  60.  
  61. void sort_data_file(int byname)
  62. {
  63.   int c, i;
  64.   FileEntry *fe, **felist;
  65.   if (file_entries == 0)
  66.     return;
  67.   for (c=0, fe=file_entries; fe; fe=fe->next)
  68.     c++;
  69.   felist = (FileEntry **)malloc(c * sizeof(FileEntry *));
  70.   for (i=0, fe=file_entries; fe; fe=fe->next, i++)
  71.     felist[i] = fe;
  72.   qsort(felist, c, sizeof(FileEntry *), byname ? entry_compare_n : entry_compare_dn);
  73.   for (i=0; i<c-1; i++)
  74.     felist[i]->next = felist[i+1];
  75.   felist[i]->next = 0;
  76.   file_entries = felist[0];
  77.   free(felist);
  78. }
  79.  
  80. void show_data_file(void)
  81. {
  82.   FileEntry *fe;
  83.   int count = 0;
  84.   printf("\nContents of distribution (M=Mandatory, I=Installing):\n");
  85.   for (fe=file_entries; fe; fe=fe->next)
  86.   {
  87.     if (count == 0)
  88.     {
  89.       printf("Disk M I Name          Size   Description\n");
  90.       count = 20;
  91.     }
  92.     ansi(ansibold);
  93.     if (fe->mandatory)
  94.       ansi("\033[33m");
  95.     if (fe->desired == 1)
  96.       ansi("\033[32m");
  97.     if (fe->desired == 2)
  98.       ansi("\033[0m");
  99.     if (fe->disk_no)
  100.       printf("%4d", fe->disk_no);
  101.     else
  102.       fputs("    ", stdout);
  103.     printf(" %c %c %-12s",
  104.       "NY"[fe->mandatory],
  105.       "?YN"[fe->desired],
  106.       fe->file_name);
  107.     printf(" %s %s\n", kb(fe->size_uncompressed), fe->description);
  108.     ansi(ansinorm);
  109.     if (--count == 0)
  110.     {
  111.       printf("<Space> for next screen, <Escape> to end listing : ");
  112.       while (1)
  113.       {
  114.         int c = getch();
  115.         if (c == ' ')
  116.         {
  117.           printf("More!\n");
  118.           break;
  119.         }
  120.         else if (c == 27)
  121.         {
  122.           printf("Skip\n");
  123.           printf("\n");
  124.           return;
  125.         }
  126.         else
  127.         {
  128.           putchar(7);
  129.           break;
  130.         }
  131.       }
  132.     }
  133.   }
  134.   printf("\n");
  135. }
  136.